What is available-typed-arrays?
The available-typed-arrays npm package provides a simple way to list all available typed array constructors in the current environment. This can be particularly useful for applications that need to work with binary data in a way that is compatible across different platforms and JavaScript environments. It helps in identifying which typed arrays are supported, allowing developers to write more adaptable and robust code.
What are available-typed-arrays's main functionalities?
Listing available typed arrays
This feature allows you to retrieve an array of strings representing the names of all available typed array constructors. The code sample demonstrates how to use the package to get the list of available typed arrays and then log them to the console.
const availableTypedArrays = require('available-typed-arrays');
const typedArrays = availableTypedArrays();
console.log(typedArrays);
Other packages similar to available-typed-arrays
typedarray
The 'typedarray' package provides a polyfill for TypedArray functionality for older browsers that do not support the latest JavaScript standards. While 'available-typed-arrays' helps in identifying available typed arrays in the environment, 'typedarray' aims to fill the gap by providing the functionality itself when it's not natively available. This makes 'typedarray' more focused on compatibility and polyfilling, whereas 'available-typed-arrays' is more about detection and adaptability.
buffer
The 'buffer' package is a node.js library for binary data manipulation. It provides a way to work with binary data through a Buffer class, which is similar to the typed arrays in JavaScript. While 'buffer' is more about providing a comprehensive set of tools for binary data manipulation, 'available-typed-arrays' focuses on identifying which typed array constructors are available in the current environment. 'buffer' can be seen as complementary to 'available-typed-arrays' for applications that need both data manipulation and environment adaptability.
available-typed-arrays
Returns an array of Typed Array names that are available in the current environment.
Example
var availableTypedArrays = require('available-typed-arrays');
var assert = require('assert');
assert.deepStrictEqual(
availableTypedArrays().sort(),
[
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'BigInt64Array',
'BigUint64Array'
].sort()
);
Tests
Simply clone the repo, npm install
, and run npm test